package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.SaleArea;
import com.sl.au.repository.SaleAreaRepository;
import com.sl.au.service.SaleAreaService;

@Service("SaleAreaService")
@Transactional
public class SaleAreaServiceImpl extends BaseServiceImpl implements SaleAreaService {

	@Autowired
	SaleAreaRepository saleAreaRepository;

	@Override
	public List<SaleArea> getPage(int start, int length, String key, String orderName, String dir) {
		Page<SaleArea> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "superior","areaCode");
		pages = saleAreaRepository.findAll(pageable);
		return pages.getContent();
	}

	@Override
	public List<SaleArea> getSaleAreas(int start, int length, String key, String orderName, String dir) {
		Page<SaleArea> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "superior","areaCode");
		pages = saleAreaRepository.findSaleArea(key, pageable);
		return pages.getContent();
	}

	public SaleAreaRepository getRepository() {
		return this.saleAreaRepository;
	}

	
}
